package com.eastmelon.tcp;

import java.io.InputStream;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

public class Browser {
	public static void main(String[] args) throws Exception {
		ServerSocket ss=new ServerSocket(10006);
		while(true){
			Socket s=ss.accept();
			new Thread(new BrowserThread(s)).start();
		}
	}
}
class BrowserThread implements Runnable {
	private Socket s;

	public BrowserThread(Socket s) {
		this.s = s;
	}

	public void run() {
		System.out.println(s.getInetAddress().getHostAddress() + "....connected");
		try {
			System.err.println(s.getInetAddress().getHostAddress());
			InputStream in=s.getInputStream();
			byte[] buf=new byte[1024];
			int len=in.read(buf);
			System.out.println(new String(buf,0,len));
			PrintWriter out = new PrintWriter(s.getOutputStream(), true);
			out.println("你好，浏览器");
			s.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}

}
